/*
 * Team Name: Focus
 * Team Members: Diana Groun, Edward Bassan
 * File Name; cpu.c
 * Description: This file contains the methods that a cpu will use
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "memory.h"
#include "cpu.h"

// Constructor.
CpuPtr newCpu(void) {
	CpuPtr cpu = (CpuPtr) malloc(sizeof(CpuStr));
	cpu->registers = newRegisterFile();
	cpu->alu = aluConstructor();
	cpu->IR = newRegister();
	cpu->MAR = newRegister();
	cpu->PC = newRegister();
	cpu->PC->setRegister(cpu->PC, 0x3000);

	cpu->SW = newRegister();

	cpu->MDR = newRegister();
	// pointers to functions.
	cpu->displayCpuRegisters = displayCpuRegisters;
	return cpu;
}

/*
 * Displays the Cpu registers
 */
int displayCpuRegisters(CpuPtr this) {
	printf("SW: %X%X%X%X\tIR: %.4X\tPC: %.4X", this->alu->negFlag,
			this->alu->zeroFlag, this->alu->carryFlag, this->alu->overflowFlag,
			this->IR->value, this->PC->value);
	return NO_ERROR;
}
///**
// * Test for cpu.h
// */
//int main(void)
//{
//      CpuPtr cpu = newCpu();
//      cpu->operandA->value = 0x0004;
//      cpu->operandB->value = 0x0002;
//      printf("Cpu OperandA %X\n",cpu->operandA->value);
//      printf("Cpu OperandB %X\n",cpu->operandB->value);
//      cpu->add_in_cpu(cpu);
//      printf("Cpu Result: %X\n",cpu->resultR->value);
//      return 0;
//}
